<template>
  <div>
    <a href="#/home">首页</a>
    <a href="#/movie">电影</a>
    <a href="#/music">音乐</a>
    <component :is="comName"></component>
  </div>
</template>

<script>
import MyHome from "@/components/MyHome.vue";
import MyMovie from "@/components/MyMovie.vue";
import MyMusic from "@/components/MyMusic.vue";
export default {
  data() {
    return {
      comName: "MyHome",
    };
  },
  components: {
    MyHome,
    MyMovie,
    MyMusic,
  },
  created() {
    //created组件创建后会自动执行
    window.addEventListener("hashchange", () => {
      const hash = location.hash;
      if (hash === "#/home") {
        this.comName = "MyHome";
      } else if (hash === "#/movie") {
        this.comName = "MyMovie";
      } else if (hash === "#/music") {
        this.comName = "MyMusic";
      }
    });
  },
};
</script>

<style>
</style>